package com.example.qxfw.dysjrh.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.qxfw.dysjrh.dto.AtmosphericDto;
import com.example.qxfw.dysjrh.entity.vo.AtmosphericVo;
import com.example.qxfw.dysjrh.mapper.AtmosphericMapper;
import com.example.qxfw.dysjrh.service.AtmosphericService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

@Service
@RequiredArgsConstructor
public class AtmosphericServiceImpl implements AtmosphericService {

    private final AtmosphericMapper atmosphericMapper;
    @DS("slave_qxdata")
    @Transactional
    @Override
    public List<AtmosphericVo> getAtmospheric(AtmosphericDto atmosphericDto) {
        LocalDateTime startTime = atmosphericDto.getStartTime();
        LocalDateTime endTime = atmosphericDto.getEndTime();
        String atmosphericTimeType = atmosphericDto.getAtmosphericTimeType();
        String stationName = atmosphericDto.getStationName();
        if ("1".equals(atmosphericTimeType)){
            return atmosphericMapper.getAtmosphericHour(startTime,endTime,stationName);
        }else {
            return atmosphericMapper.getAtmosphericDay(startTime,endTime,stationName);
        }
    }
}
